home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / objc / zone.h < prev   
Text File  |  1991-10-14  |  2KB  |  89 lines

  1. #import <stddef.h>
  2.  
  3. /*
  4.  * Interface to zone based malloc.
  5.  */
  6.  
  7. typedef struct _NXZone {
  8.     void *(*realloc)(struct _NXZone *zonep, void *ptr, size_t size);
  9.     void *(*malloc)(struct _NXZone *zonep, size_t size);
  10.     void (*free)(struct _NXZone *zonep, void *ptr);
  11.     void (*destroy)(struct _NXZone *zonep);
  12.           /* Implementation specific entries */
  13.           /* Do not depend on the size of this structure */
  14. } NXZone;
  15.  
  16. #define NX_NOZONE  ((NXZone *)0)
  17.  
  18. /*
  19.  * Returns the default zone used by the malloc(3) calls.
  20.  */
  21. extern NXZone *NXDefaultMallocZone(void);
  22.  
  23. /* 
  24.  * Create a new zone with its own memory pool.
  25.  * If canfree is 0 the allocator will never free memory and mallocing will be fast
  26.  */
  27. extern NXZone *NXCreateZone(size_t startSize, size_t granularity, int canFree);
  28.  
  29. /*
  30.  * Create a new zone who obtains memory from another zone.
  31.  * Returns NX_NOZONE if the passed zone is already a child.
  32.  */
  33. extern NXZone  *NXCreateChildZone(NXZone *parentZone, size_t startSize, size_t granularity, int canFree);
  34.  
  35. /*
  36.  * The zone is destroyed and all memory reclaimed.
  37.  */
  38. #define NXDestroyZone(zonep) \
  39.     ((*(zonep)->destroy)(zonep))
  40.     
  41. /*
  42.  * Will merge zone with the parent zone. Malloced areas are still valid.
  43.  * Must be an child zone.
  44.  */
  45. extern void NXMergeZone(NXZone *zonep);
  46.  
  47. #define NXZoneMalloc(zonep, size) \
  48.     ((*(zonep)->malloc)(zonep, size))
  49.  
  50. #define NXZoneRealloc(zonep, ptr, size) \
  51.     ((*(zonep)->realloc)(zonep, ptr, size))
  52.     
  53. #define NXZoneFree(zonep, ptr) \
  54.     ((*(zonep)->free)(zonep, ptr))
  55.  
  56. /*
  57.  * Calls NXZoneMalloc and then bzero.
  58.  */
  59. extern void *NXZoneCalloc(NXZone *zonep, size_t numElems, size_t byteSize);
  60.  
  61. /*
  62.  * Returns the zone for a pointer.
  63.  * NX_NOZONE if not in any zone.
  64.  * The ptr must have been returned from a malloc or realloc call.
  65.  */
  66. extern NXZone *NXZoneFromPtr(void *ptr);
  67.  
  68. /*
  69.  * Debugging Helpers.
  70.  */
  71.  
  72.  /*  
  73.   * Will print to stdout if this pointer is in the malloc heap, free status, and size.
  74.   */
  75. extern void NXZonePtrInfo(void *ptr);
  76.  
  77. /*
  78.  * Will verify all internal malloc information.
  79.  * This is what malloc_debug calls.
  80.  */
  81. extern int NXMallocCheck(void);
  82.  
  83. /*
  84.  * Give a zone a name.
  85.  *
  86.  * The string will be copied.
  87.  */
  88. extern void NXNameZone(NXZone *z, const char *name);
  89.